set more off

use "ANES 2008 - RAW.dta"

********Experiment Version for Old/New*****
gen version = V082402 - 1
label var version "Version of Questions"
label def ver 1 "New" 0 "Old"
label values version ver
tab version V082402


**********Dependent Variable: Vote Choice****************
gen vote = . 
replace vote = 1 if V085044a == 3
replace vote = 0 if V085044a == 1
label var vote "Vote Choice" 
label def vot 1 "McCain" 0 "Obama"
label values vote vot


**********Information************
foreach var in V085066 V085067 V085120a V085121a V085122a V085123a {
	tab `var'
	}
	
	label def corre 1 "Correct" 0 "Incorrect/No Guess"
	recode V085066 (-9=.) (-8=0) (-2=.) (1=1) (5=0), gen(house)
	recode V085067 (-9=.) (-8=0) (-2=.) (1=1) (5=0), gen(senate)
	label values house corre
	label values senate corre
	
	tab house
	tab senate
	tab house senate, row col
	by V083303, sort: tab house
	by V083303, sort: tab senate
	
	egen info = rowtotal(senate house), missing
	tab info
	
	
	recode  V083303 (1=5) (2=4) (3=3) (4=2) (5=1) (-4=.), gen(int_knowl)
	
	


**********Main Ind. Variable: Policy Attitude, Importance, Proximity****************

****Defense Spending***

*own attitude, placements*
rename V083112 defense2008old 
gen defense2008new = . 
replace defense2008new = 1 if V083115x == 7
replace defense2008new = 2 if V083115x == 6
replace defense2008new = 3 if V083115x == 5
replace defense2008new = 4 if V083115x == 4
replace defense2008new = 5 if V083115x == 3
replace defense2008new = 6 if V083115x == 2
replace defense2008new = 7 if V083115x == 1
label def defnew 1 "A Lot Less" 7 "A Lot More"
label values defense2008new defnew

rename V083114a obama2008defenseold 
rename V083114b mccain2008defenseold

gen obama2008defensenew = . 
replace obama2008defensenew = 1 if V083117x == 7
replace obama2008defensenew = 2 if V083117x == 6
replace obama2008defensenew = 3 if V083117x == 5
replace obama2008defensenew = 4 if V083117x == 4
replace obama2008defensenew = 5 if V083117x == 3
replace obama2008defensenew = 6 if V083117x == 2
replace obama2008defensenew = 7 if V083117x == 1

gen mccain2008defensenew = . 
replace mccain2008defensenew = 1 if V083118x == 7
replace mccain2008defensenew = 2 if V083118x == 6
replace mccain2008defensenew = 3 if V083118x == 5
replace mccain2008defensenew = 4 if V083118x == 4
replace mccain2008defensenew = 5 if V083118x == 3
replace mccain2008defensenew = 6 if V083118x == 2
replace mccain2008defensenew = 7 if V083118x == 1
label values mccain2008defensenew defnew
label values obama2008defensenew defnew

mvdecode defense2008old obama2008defenseold mccain2008defenseold, mv(-9 = . \ -8 = . \ -7 = . \ -1 = . )


**proximity*
	*Old
		summarize obama2008defenseold mccain2008defenseold
			*old*
				*mccain: 5.391867
				*obama: 3.693533
		*City Block: Sample
			gen defense2008proxold = abs(defense2008old - 3.693533) - abs(defense2008old - 5.391867)

		*Cit Block: Informed
			summ obama2008defenseold mccain2008defenseold if info == 2 & int_knowl  >= 4 & int_knowl <= 5
				*obama: 3.316667
				*mccain: 5.615385
			gen defense2008proxold_info = abs(defense2008old - 3.316667 ) - abs(defense2008old - 5.615385)
			
		*City Block: Self 
			gen defense2008proxold_self =  abs(defense2008old - obama2008defenseold ) - abs(defense2008old - mccain2008defenseold)
		
		*Euclidean
			gen defense2008proxold_euclid1 = [(defense2008old - 3.693533)*(defense2008old - 3.693533) ] - [ (defense2008old - 5.391867)*(defense2008old - 5.391867) ] 
			gen defense2008proxold_euclid2 = [ (defense2008old - 3.316667 )*(defense2008old - 3.316667)] - [(defense2008old - 5.615385)*(defense2008old - 5.615385)] 
			gen defense2008proxold_euclid3 = [(defense2008old - obama2008defenseold )*(defense2008old - obama2008defenseold )] - [(defense2008old - mccain2008defenseold)*(defense2008old - mccain2008defenseold) ] 

	*New
		summarize obama2008defensenew mccain2008defensenew
			*obama: 3.22083
			*mccain: 5.128599
		*City Block: Sample
			gen defense2008proxnew = abs(defense2008new - 3.22083) - abs(defense2008new - 5.128599)

		*Cit Block: Informed
			summarize obama2008defensenew mccain2008defensenew if info == 2 & int_knowl  >= 4 & int_knowl <= 5
				*obama: 2.838509
				*mccain: 5.269006
	
			gen defense2008proxnew_info = abs(defense2008new - 2.838509) - abs(defense2008new - 5.269006)

		*City Block: Self
			gen defense2008proxnew_self = abs(defense2008new - obama2008defensenew) - abs(defense2008new - mccain2008defensenew)

		
		*Euclidean
			gen defense2008proxnew_euclid1 = [(defense2008new - 3.22083) *(defense2008new - 3.22083) ] - [(defense2008new - 5.128599) * (defense2008new - 5.128599)]
			gen defense2008proxnew_euclid2 = [(defense2008new - 2.838509)*(defense2008new - 2.838509)] - [(defense2008new - 5.269006)*(defense2008new - 5.269006)]
			gen defense2008proxnew_euclid3 = [(defense2008new - obama2008defensenew)*(defense2008new - obama2008defensenew)] - [(defense2008new - mccain2008defensenew)*(defense2008new - mccain2008defensenew)]

		summ defense2008proxnew defense2008proxnew_self defense2008proxnew_info defense2008proxnew_euclid1 defense2008proxnew_euclid2 defense2008proxnew_euclid3


		*Combined Index (City Sample)

			gen defense2008both = defense2008old
			replace defense2008both = defense2008new if defense2008both == . 

			gen mccain2008defenseboth = mccain2008defenseold
			replace mccain2008defenseboth = mccain2008defensenew if mccain2008defenseboth == . 

			gen obama2008defenseboth = obama2008defenseold
			replace obama2008defenseboth = obama2008defensenew if obama2008defenseboth == . 
			
			summ mccain2008defenseboth obama2008defenseboth
			gen defense2008bothprox = abs(defense2008both - 3.510456) - abs(defense2008both - 5.262712)


*attitude strength*
gen defense2008extold = .
replace defense2008extold = 1 if defense2008old == 4
replace defense2008extold = 2 if defense2008old == 3
replace defense2008extold = 2 if defense2008old == 5
replace defense2008extold = 3 if defense2008old == 2
replace defense2008extold = 3 if defense2008old == 6
replace defense2008extold = 4 if defense2008old == 1
replace defense2008extold = 4 if defense2008old == 7

gen defense2008extnew = . 
replace defense2008extnew = 1 if defense2008new == 4
replace defense2008extnew = 2 if defense2008new == 3
replace defense2008extnew = 2 if defense2008new == 5
replace defense2008extnew = 3 if defense2008new == 2
replace defense2008extnew = 3 if defense2008new == 6
replace defense2008extnew = 4 if defense2008new == 1
replace defense2008extnew = 4 if defense2008new == 7

gen defense2008ext = defense2008extold
replace defense2008ext = defense2008extnew if defense2008ext == . 


rename V083113 defense2008impold  
rename V083116 defense2008impnew 
mvdecode defense2008impold defense2008impnew, mv(-9 = . \ -8 = . \ -1 = .)

gen defense2008imp = defense2008impold
replace defense2008imp = defense2008impnew if defense2008imp == . 


*standardized*
foreach var in defense2008proxold defense2008proxold_info defense2008proxold_self defense2008proxold_euclid1 defense2008proxold_euclid2 ///
	defense2008proxold_euclid3 defense2008proxnew defense2008proxnew_self defense2008proxnew_info defense2008proxnew_euclid1  ///
	defense2008proxnew_euclid2 defense2008proxnew_euclid3 defense2008bothprox ///
	defense2008extnew defense2008extold defense2008ext defense2008impnew defense2008impold defense2008imp {
		qui sum `var'
		gen `var'01 = (`var' - `r(min)') / (`r(max)'-`r(min)')
	}

	label var defense2008proxold01 "Defense:Prox"
	label var defense2008impold01 "Defense:Imp"
	
	label var defense2008proxnew01 "Defense:Prox"
	label var defense2008impnew01 "Defense:Imp"
	

	
***Spending and Services***
*own attitude, placements*
gen spend2008old = .
replace spend2008old = 1 if V083105 == 7
replace spend2008old = 2 if V083105 == 6
replace spend2008old = 3 if V083105 == 5
replace spend2008old = 4 if V083105 == 4
replace spend2008old = 5 if V083105 == 3
replace spend2008old = 6 if V083105 == 2
replace spend2008old = 7 if V083105 == 1

gen obamaspend2008old = . 
replace obamaspend2008old = 1 if V083107a == 7
replace obamaspend2008old = 2 if V083107a == 6
replace obamaspend2008old = 3 if V083107a == 5
replace obamaspend2008old = 4 if V083107a == 4
replace obamaspend2008old = 5 if V083107a == 3
replace obamaspend2008old = 6 if V083107a == 2
replace obamaspend2008old = 7 if V083107a == 1

gen mccainspend2008old = . 
replace mccainspend2008old = 1 if V083107b == 7
replace mccainspend2008old = 2 if V083107b == 6
replace mccainspend2008old = 3 if V083107b == 5
replace mccainspend2008old = 4 if V083107b == 4
replace mccainspend2008old = 5 if V083107b == 3
replace mccainspend2008old = 6 if V083107b == 2
replace mccainspend2008old = 7 if V083107b == 1

label def spen 1 "More Services" 7 "Fewer Services"
label values mccainspend2008old spen1
label values obamaspend2008old spen1
label values spend2008old spen1

rename V083108x spend2008new
rename V083110x obamaspend2008new
rename V083111x mccainspend2008new


mvdecode spend2008new obamaspend2008new mccainspend2008new, mv(-9 = . \ -8 = . \ -7 = . \ -1 = . )

summ spend2008old spend2008new mccainspend2008old mccainspend2008new obamaspend2008old obamaspend2008new 
*proximity*

	*Old
		summ mccainspend2008old obamaspend2008old
			*old
			*mccain: 4.369159
			*obama: 2.700555
		*City Block: Sample
		gen spend2008proxold = abs(spend2008old - 2.700555) - abs(spend2008old - 4.369159)
	
		*Cit Block: Informed
		summ mccainspend2008old obamaspend2008old 	if info == 2 & int_knowl  >= 4 & int_knowl <= 5
			*mccain: 4.823204 
			*obama:  2.211111
			
		gen spend2008proxold_info  = abs(spend2008old - 2.211111) - abs(spend2008old - 4.823204 )

		*City Block: Self
		gen spend2008proxold_self = abs(spend2008old - obamaspend2008old) - abs(spend2008old - mccainspend2008old)

		*Euclidean
		gen spend2008proxold_euclid1 = [(spend2008old - 2.700555)*(spend2008old - 2.700555)  ] - [(spend2008old - 4.369159)*(spend2008old - 4.369159)  ] 
		gen spend2008proxold_euclid2 = [(spend2008old - 2.211111)*(spend2008old - 2.211111)  ] - [ (spend2008old - 4.823204 )*(spend2008old - 4.823204 ) ] 
		gen spend2008proxold_euclid3 = [(spend2008old - obamaspend2008old)*(spend2008old - obamaspend2008old)  ] - [(spend2008old - mccainspend2008old)*(spend2008old - mccainspend2008old)  ] 
	
		summ spend2008proxold spend2008proxold_info spend2008proxold_self spend2008proxold_euclid1 spend2008proxold_euclid2 spend2008proxold_euclid3
		
		
	*New
		*City Block: Sample 
		summ mccainspend2008new obamaspend2008new 
			*new
			*mccain: 4.145594
			*obama: 2.685255
		gen spend2008proxnew = abs(spend2008new - 2.685255) - abs(spend2008new - 4.145594)

		*Cit Block: Informed
		summ mccainspend2008new obamaspend2008new if info == 2 & int_knowl  >= 4 & int_knowl <= 5
			*mccain:  4.906433  
			*obama:  2.306358 
		gen spend2008proxnew_info = abs(spend2008new - 2.306358 ) - abs(spend2008new - 4.906433 )
		
		*City Block: Self
		gen spend2008proxnew_self = abs(spend2008new - obamaspend2008new) - abs(spend2008new - mccainspend2008new)

		*Euclidean
		gen spend2008proxnew_euclid1 = [(spend2008new - 2.685255)*(spend2008new - 2.685255)  ] - [(spend2008new - 4.145594)*(spend2008new - 4.145594)  ] 
		gen spend2008proxnew_euclid2 = [(spend2008new - 2.306358 )*(spend2008new - 2.306358 )  ] - [ (spend2008new - 4.906433 )*(spend2008new - 4.906433 ) ] 
		gen spend2008proxnew_euclid3 = [(spend2008new - obamaspend2008new)*(spend2008new - obamaspend2008new)  ] - [(spend2008new - mccainspend2008new)*(spend2008new - mccainspend2008new)] 
		
		summ spend2008proxnew spend2008proxnew_info spend2008proxnew_self spend2008proxnew_euclid1 spend2008proxnew_euclid2 spend2008proxnew_euclid3


	*Combined Index (City Sample)
		gen spend2008both = spend2008old
		replace spend2008both = spend2008new if spend2008both == . 

		gen mccainspend2008both = mccainspend2008old
		replace mccainspend2008both = mccainspend2008new if mccainspend2008both == . 

		gen obamaspend2008both = obamaspend2008old
		replace obamaspend2008both = obamaspend2008new if obamaspend2008both == . 

		gen spend2008bothprox = abs(spend2008both - 2.692991) - abs(spend2008both - 4.258751)


*attitude strength*
gen spend2008extold = . 
replace spend2008extold = 1 if spend2008old == 4
replace spend2008extold = 2 if spend2008old == 3
replace spend2008extold = 2 if spend2008old == 5
replace spend2008extold = 3 if spend2008old == 2
replace spend2008extold = 3 if spend2008old == 6
replace spend2008extold = 4 if spend2008old == 1
replace spend2008extold = 4 if spend2008old == 7

gen spend2008extnew = . 
replace spend2008extnew = 1 if spend2008new == 4
replace spend2008extnew = 2 if spend2008new == 3
replace spend2008extnew = 2 if spend2008new == 5
replace spend2008extnew = 3 if spend2008new == 2
replace spend2008extnew = 3 if spend2008new == 6
replace spend2008extnew = 4 if spend2008new == 1
replace spend2008extnew = 4 if spend2008new == 7

gen spend2008ext = spend2008extold
replace spend2008ext = spend2008extnew  if spend2008ext == .

rename V083106 spend2008impold 
rename V083109 spend2008impnew 
mvdecode spend2008impold spend2008impnew, mv(-9 = . \ -8 = . \ -7 = . \ -1 = . )
gen spend2008imp = spend2008impold
replace spend2008imp = spend2008impnew if spend2008imp == . 



*standardized*
foreach var in spend2008proxold spend2008proxold_info spend2008proxold_self spend2008proxold_euclid1 spend2008proxold_euclid2 spend2008proxold_euclid3 spend2008proxnew ///
		spend2008proxnew_info spend2008proxnew_self spend2008proxnew_euclid1 spend2008proxnew_euclid2 spend2008proxnew_euclid3 spend2008bothprox  ///
		spend2008extnew spend2008extold spend2008ext spend2008impnew spend2008impold spend2008imp {
			qui sum `var'
			gen `var'01 = (`var' - `r(min)') / (`r(max)'-`r(min)')
		}

	label var spend2008proxold01 "Spend:Prox"
	label var spend2008impold01 "Spend:Imp"
	label var spend2008proxnew01 "Spend:Prox"
	label var spend2008impnew01 "Spend:Imp"
		

		
**Jobs***
*own attitude, placements*
rename V083128 jobs2008
rename V083130b mccainjobs2008
rename V083130a obamajobs2008
mvdecode jobs2008 mccainjobs2008 obamajobs2008, mv(-9 = . \ -8 = . \ -1 = . \ -7 = . )

*proximity*
	*City Block: Sample
	summ *jobs2008
	*mccain 5.159113
	*obama 3.113985 
	gen jobs2008prox = abs(jobs2008 - 3.113985) - abs(jobs2008 - 5.159113)

	*City Block: Informed
	summ *jobs2008 if info == 2 & int_knowl  >= 4 & int_knowl <= 5
	*mccain:  5.44382
	*obama 2.655367
	gen jobs2008prox_info = abs(jobs2008 - 2.655367) - abs(jobs2008 - 5.44382)

	*City Block: Self
	gen jobs2008prox_self = abs(jobs2008 - obamajobs2008) - abs(jobs2008 - mccainjobs2008)

	*Euclidean
	gen jobs2008prox_euclid1 = [(jobs2008 - 3.113985)*(jobs2008 - 3.113985) ] - [(jobs2008 - 5.159113)*(jobs2008 - 5.159113) ] 
	gen jobs2008prox_euclid2 = [(jobs2008 - 2.655367)*(jobs2008 - 2.655367) ] - [(jobs2008 - 5.44382)*(jobs2008 - 5.44382)  ] 
	gen jobs2008prox_euclid3 = [(jobs2008 - obamajobs2008)*(jobs2008 - obamajobs2008)  ] - [(jobs2008 - mccainjobs2008)*(jobs2008 - mccainjobs2008)  ] 
	
	summ jobs2008prox jobs2008prox_info jobs2008prox_self jobs2008prox_euclid1 jobs2008prox_euclid2 jobs2008prox_euclid3
	

*attitude strength*
gen jobs2008ext = . 
replace jobs2008ext = 1 if jobs2008 == 4
replace jobs2008ext = 2 if jobs2008 == 3
replace jobs2008ext = 2 if jobs2008 == 5
replace jobs2008ext = 3 if jobs2008 == 2
replace jobs2008ext = 3 if jobs2008 == 6
replace jobs2008ext = 4 if jobs2008 == 1
replace jobs2008ext = 4 if jobs2008 == 7

rename V083129 jobs2008imp 
mvdecode jobs2008imp, mv(-9 = . \ -8 = . \ -1 = .)

*standardized*

foreach var in  jobs2008prox jobs2008prox_info jobs2008prox_self jobs2008prox_euclid1 jobs2008prox_euclid2 jobs2008prox_euclid3 jobs2008ext jobs2008imp {
		qui sum `var'
		gen `var'01 = (`var' - `r(min)') / (`r(max)'-`r(min)')
	}

	label var jobs2008prox01 "Jobs:Prox"
	label var jobs2008imp01 "Jobs:Imp"
	
	

**Aid to Blacks***
*own attitude, placements*
rename V083137 blackaid2008
rename V083139a obamablackaid2008
rename V083139b mccainblackaid2008
mvdecode blackaid2008 obamablackaid2008 mccainblackaid2008, mv(-9 = . \ -8 = . \ -1 = . \ -7 = .)

*proximity*
	*city Block: Sample
	summ *blackaid2008
	*obama 3.117448
	*mccain 4.959535
	gen blackaid2008prox = abs(blackaid2008 - 3.117448) - abs(blackaid2008 - 4.959535)
	*city block: informed
	summ *blackaid2008 if info == 2	& int_knowl  >= 4 & int_knowl <= 5
	*obama  2.870588  
	*mccain  5.106061 
	gen blackaid2008prox_info = abs(blackaid2008 -  2.870588) - abs(blackaid2008 -  5.106061)
	*city block: self
	gen blackaid2008prox_self = abs(blackaid2008 - obamablackaid2008) - abs(blackaid2008 - mccainblackaid2008)
	*euclidean
	gen blackaid2008prox_euclid1 = [(blackaid2008 - 3.117448)*(blackaid2008 - 3.117448) ] - [(blackaid2008 - 4.959535)*(blackaid2008 - 4.959535)] 
	gen blackaid2008prox_euclid2 = [(blackaid2008 -  2.870588)*(blackaid2008 -  2.870588)  ] - [(blackaid2008 -  5.106061)*(blackaid2008 -  5.106061)  ] 
	gen blackaid2008prox_euclid3 = [ (blackaid2008 - obamablackaid2008)*(blackaid2008 - obamablackaid2008) ] - [(blackaid2008 - mccainblackaid2008)*(blackaid2008 - mccainblackaid2008)] 

	summ blackaid2008prox blackaid2008prox_info blackaid2008prox_self blackaid2008prox_euclid1 blackaid2008prox_euclid2 blackaid2008prox_euclid3	

*attitude strength*
gen blackaid2008ext =  . 
replace blackaid2008ext = 1 if blackaid2008 == 4
replace blackaid2008ext = 2 if blackaid2008 == 3
replace blackaid2008ext = 2 if blackaid2008 == 5
replace blackaid2008ext = 3 if blackaid2008 == 2
replace blackaid2008ext = 3 if blackaid2008 == 6
replace blackaid2008ext = 4 if blackaid2008 == 1
replace blackaid2008ext = 4 if blackaid2008 == 7

rename V083138a blackaid2008impold
rename V083138b blackaid2008impnew
mvdecode blackaid2008impold blackaid2008impnew, mv(-9 = . \ -8 = . \ -1 = .)

gen blackaid2008imp = .
replace blackaid2008imp = blackaid2008impold
replace blackaid2008imp = blackaid2008impnew if blackaid2008imp == .


*standardized*
foreach var in blackaid2008prox blackaid2008prox_info blackaid2008prox_self blackaid2008prox_euclid1 blackaid2008prox_euclid2 blackaid2008prox_euclid3	///
		blackaid2008ext blackaid2008impnew blackaid2008impold blackaid2008imp {
		qui sum `var'
		gen `var'01 = (`var' - `r(min)') / (`r(max)'-`r(min)')
	}
	
	label var blackaid2008prox01 "BlackAid:Prox"
	label var blackaid2008impold01 "BlackAid:Imp"
	label var blackaid2008impnew01 "BlackAid:Imp"
	


**Environment vs. Jobs***
*own attitude, placements*
rename V083154 envirojobs2008
rename V083156a obamaenvirojobs2008
rename V083156b mccainenvirojobs2008
mvdecode envirojobs2008 obamaenvirojobs2008 mccainenvirojobs2008, mv(-9 = . \ -8 = . \ -7 = . \ -1 = .)

*proximity*
	summ *envirojobs2008
		*obama: 3.852391
		*mccain: 4.435871
	*City Block: Sample
		gen envirojobs2008prox = abs(envirojobs2008 - 3.852391) - abs(envirojobs2008 - 4.35971)	
	*City Block: Informed
		summ *envirojobs2008 if info == 2	& int_knowl  >= 4 & int_knowl <= 5
			*obama: 3.401163
			*mccain: 4.695906   
		gen envirojobs2008prox_info = abs(envirojobs2008 - 3.401163) - abs(envirojobs2008 - 4.695906)	
	*City Block: Self
		gen envirojobs2008prox_self = abs(envirojobs2008 - obamaenvirojobs2008) - abs(envirojobs2008 - mccainenvirojobs2008)	
	*Euclidean
		gen envirojobs2008prox_euclid1 = [(envirojobs2008 - 3.852391)*(envirojobs2008 - 3.852391)] - [(envirojobs2008 - 4.35971)*(envirojobs2008 - 4.35971)	] 
		gen envirojobs2008prox_euclid2 = [(envirojobs2008 - 3.401163)*(envirojobs2008 - 3.401163)] - [(envirojobs2008 - 4.695906)*(envirojobs2008 - 4.695906)] 
		gen envirojobs2008prox_euclid3 = [(envirojobs2008 - obamaenvirojobs2008)*(envirojobs2008 - obamaenvirojobs2008)] - [(envirojobs2008 - mccainenvirojobs2008)*(envirojobs2008 - mccainenvirojobs2008)]

	
	summ envirojobs2008prox envirojobs2008prox_info envirojobs2008prox_self envirojobs2008prox_euclid1 ///
			envirojobs2008prox_euclid2 envirojobs2008prox_euclid3

*attitude strength*
	gen envirojobs2008ext = .
	replace envirojobs2008ext = 1 if envirojobs2008 == 4
	replace envirojobs2008ext = 2 if envirojobs2008 == 3
	replace envirojobs2008ext = 2 if envirojobs2008 == 5
	replace envirojobs2008ext = 3 if envirojobs2008 == 2
	replace envirojobs2008ext = 3 if envirojobs2008 == 6
	replace envirojobs2008ext = 4 if envirojobs2008 == 1
	replace envirojobs2008ext = 4 if envirojobs2008 == 7

	rename V083155 envirojobs2008imp
	mvdecode envirojobs2008imp, mv(-9 = . \ -8 = . \ -1 = .) 


	foreach var in  envirojobs2008prox envirojobs2008prox_info envirojobs2008prox_self envirojobs2008prox_euclid1 envirojobs2008prox_euclid2 ///
		envirojobs2008prox_euclid3 envirojobs2008ext envirojobs2008imp {
			qui sum `var'
			gen `var'01 = (`var' - `r(min)') / (`r(max)'-`r(min)')
		}
		
	label var envirojobs2008imp01 "EnviroJobs:Imp"
	label var envirojobs2008prox01 "EnviroJobs:Prox"
	

****Emissions Standards**

*own attitude, placements*
	rename V083157x emission2008
	rename V083159x  obamaemission2008
	rename V083160x mccainemission2008
	mvdecode emission2008 obamaemission2008 mccainemission2008, mv(-9 = . \ -8 = . \ -1 = .)

*proximity*
	*City Block: Sample
		summ *emission2008
			*mccain: 3.427318
			*obama: 2.559524
		gen emission2008prox = abs(emission2008 - 2.559524) - abs(emission2008 - 3.427318)
	*City Block: Informed
		summ *emission2008 if info == 2	& int_knowl  >= 4 & int_knowl <= 5
			*obama:  2.161074  
			*mccain:  3.496454 
		gen emission2008prox_info = abs(emission2008 -  2.161074) - abs(emission2008 - 3.496454 )
	*City Block: Self
		gen emission2008prox_self = abs(emission2008 - obamaemission2008) - abs(emission2008 - mccainemission2008)
	*Euclidean
		gen emission2008prox_euclid1 = [(emission2008 - 2.559524)*(emission2008 - 2.559524)] - [(emission2008 - 3.427318)*(emission2008 - 3.427318)]
		gen emission2008prox_euclid2 = [(emission2008 -  2.161074)*(emission2008 -  2.161074) ] - [(emission2008 - 3.496454 )*(emission2008 - 3.496454 ) ]
		gen emission2008prox_euclid3 = [(emission2008 - obamaemission2008)*(emission2008 - obamaemission2008)] - [(emission2008 - mccainemission2008)*(emission2008 - mccainemission2008)]

	summ emission2008prox emission2008prox_info emission2008prox_self emission2008prox_euclid1 emission2008prox_euclid2 emission2008prox_euclid3
		

*own attitude, placements*
	gen emission2008ext = . 
	replace emission2008ext = 1 if emission2008 == 4
	replace emission2008ext = 2 if emission2008 == 3
	replace emission2008ext = 2 if emission2008 == 5
	replace emission2008ext = 3 if emission2008 == 2
	replace emission2008ext = 3 if emission2008 == 6
	replace emission2008ext = 4 if emission2008 == 1
	replace emission2008ext = 4 if emission2008 == 7

	rename V083158 emission2008imp
	mvdecode emission2008imp, mv(-9 = . \ -8 = . \ -1 = . )


*standardized*
	foreach var in emission2008prox emission2008prox_info emission2008prox_self emission2008prox_euclid1 emission2008prox_euclid2 ///
		emission2008prox_euclid3 emission2008ext emission2008imp {
			qui sum `var'
			gen `var'01 = (`var' - `r(min)') / (`r(max)'-`r(min)')
		}
		
		
		label var emission2008prox01 "Emissions:Prox"
		label var emission2008imp01 "Emissions:Imp"
		
		
***Government Health INsurance***
	rename V083119 health2008
	rename V083121a obamahealth2008
	rename V083121b mccainhealth2008
	mvdecode health2008 obamahealth2008 mccainhealth2008, mv(-1 = . \ -7 = . \ -8 = . \ -9 =.)

*proximity*

	*City Block: Sample
		summ *health2008
			*obama: 2.949763
			*mccain: 5.152216
		gen health2008prox = abs(health2008 - 2.949763) - abs(health2008 - 5.152216)

	*City Block: Informed
		summ *health2008 if info == 2	& int_knowl  >= 4 & int_knowl <= 5
			*obama   2.346369  
			*mccain 5.410112 
		gen health2008prox_info = abs(health2008 - 2.346369) - abs(health2008 - 5.410112 )
	*City Block: Self
		gen health2008prox_self = abs(health2008 - obamahealth2008) - abs(health2008 - mccainhealth2008)
	*Euclidean
		gen health2008prox_euclid1 = [(health2008 - 2.949763)*(health2008 - 2.949763)] - [(health2008 - 5.152216)*(health2008 - 5.152216)] 
		gen health2008prox_euclid2 = [(health2008 - 2.346369)*(health2008 - 2.346369) ] - [(health2008 - 5.410112 )*(health2008 - 5.410112 ) ] 
		gen health2008prox_euclid3 = [(health2008 - obamahealth2008)*(health2008 - obamahealth2008) ] - [(health2008 - mccainhealth2008)*(health2008 - mccainhealth2008)] 

		summ health2008prox health2008prox_info health2008prox_self health2008prox_euclid1 health2008prox_euclid2 health2008prox_euclid3


*attitude strength*

	gen health2008ext =  . 
	replace health2008ext = 1 if health2008 == 4
	replace health2008ext = 2 if health2008 == 3
	replace health2008ext = 2 if health2008 == 5
	replace health2008ext = 3 if health2008 == 2
	replace health2008ext = 3 if health2008 == 6
	replace health2008ext = 4 if health2008 == 1
	replace health2008ext = 4 if health2008 == 7

	rename V083120 health2008imp
	mvdecode health2008imp, mv(-9 = . \ -8 = . \ -1 = .)



*standardized*
	foreach var in health2008prox health2008prox_info health2008prox_self health2008prox_euclid1 ///
		health2008prox_euclid2 health2008prox_euclid3 health2008ext health2008imp {
			qui sum `var'
			gen `var'01 = (`var' - `r(min)') / (`r(max)'-`r(min)')
		}

		
	label var health2008prox01 "Gov H. Insurance:Prox"
	label var health2008imp01 "Gov H. Insurance:Imp"
		
		
		
***universal health care***
*own atttiude, placements*
	rename V083124x universal2008
	rename V083126x obamauniversal2008
	rename V083127x mccainuniversal2008
	mvdecode universal2008 obamauniversal2008 mccainuniversal2008, mv(-1 = . \ -7 = . \ -8 = . \ -9 =.)

*proximity*

	*City Block: Sample
		summ *universal2008
			*mccain  5.123941
			*obama  2.235656
		gen universal2008prox = abs(universal2008 - 2.235656) - abs(universal2008 - 5.123941)

	*City Block: Informed
		summ *universal2008 if info == 2	& int_knowl  >= 4 & int_knowl <= 5
			*obama:  1.886228 
			*mccain:  5.804878
		gen universal2008prox_info = abs(universal2008 - 1.886228 ) - abs(universal2008 - 5.804878)
	*City Block: Self
		gen universal2008prox_self = abs(universal2008 - obamauniversal2008) - abs(universal2008 - mccainuniversal2008)

	*Euclidean
		gen universal2008prox_euclid1 = [(universal2008 - 2.235656)*(universal2008 - 2.235656) ] - [(universal2008 - 5.123941)*(universal2008 - 5.123941) ] 
		gen universal2008prox_euclid2 = [(universal2008 - 1.886228 )*(universal2008 - 1.886228 ) ] - [(universal2008 - 5.804878)*(universal2008 - 5.804878) ] 
		gen universal2008prox_euclid3 = [(universal2008 - obamauniversal2008)*(universal2008 - obamauniversal2008) ] - [(universal2008 - mccainuniversal2008)*(universal2008 - mccainuniversal2008) ] 

		
	summ universal2008prox universal2008prox_info universal2008prox_self universal2008prox_euclid1 universal2008prox_euclid2 universal2008prox_euclid3
		
		
*attitude strength*
	gen universal2008ext = . 
	replace universal2008ext = 1 if universal2008 == 	4
	replace universal2008ext = 2 if universal2008 == 	3
	replace universal2008ext = 2 if universal2008 == 	5
	replace universal2008ext = 3 if universal2008 == 	2
	replace universal2008ext = 3 if universal2008 == 	6
	replace universal2008ext = 4 if universal2008 == 	1
	replace universal2008ext = 4 if universal2008 == 	7

	rename V083125 universal2008imp
	mvdecode universal2008imp, mv(-9 = . \ -8 = . \ -1 = .)

	tab universal2008imp

*Standardization
	foreach var in universal2008prox universal2008prox_info universal2008prox_self universal2008prox_euclid1 universal2008prox_euclid2 universal2008prox_euclid3  universal2008ext universal2008imp {
			qui sum `var'
			gen `var'01 = (`var' - `r(min)') / (`r(max)'-`r(min)')
		}

		label var universal2008prox01 "Universal Health:Prox"
		label var universal2008imp01 "Universal Health:Imp"
		
	
	
**Illegial Immigrations***
*own attitude, placements*
	rename V083133x citizenship2008
	rename V083135x obamacitizenship2008
	mvdecode citizenship2008 obamacitizenship2008, mv(-1 = . \ -7 = . \ -8 = . \ -9 =.)
	*the summary republican measure has no observations, so it has to be created maually*
		gen  mccaincitizenship2008 = . 
		replace mccaincitizenship2008 =  1 if V083136 == 1  & V083136a == 1
		replace mccaincitizenship2008 =  2 if V083136 == 1  & V083136a == 2
		replace mccaincitizenship2008 =  3 if V083136 == 1  & V083136a == 3
		replace mccaincitizenship2008 =  4 if V083136 == 3  
		replace mccaincitizenship2008 =  5 if V083136 == 2  & V083136a == 3
		replace mccaincitizenship2008 =  6 if V083136 == 2  & V083136a == 2
		replace mccaincitizenship2008 =  7 if V083136 == 2  & V083136a == 1

*proximity*

	*City Block: Sample
		summ *citizenship2008
			*obama: 2.977244
			*mccain: 4.306098
		gen citizenship2008prox = abs(citizenship2008 - 2.977244) - abs(citizenship2008 - 4.306098)
	
	*City Block: Informed
		summ *citizenship2008 
			*obama 2.372263 
			*mccain  4.194245
		gen citizenship2008prox_info  = abs(citizenship2008 - 2.372263) - abs(citizenship2008 - 4.194245)
	*City Block: Self
		gen citizenship2008prox_self = abs(citizenship2008 - obamacitizenship2008) - abs(citizenship2008 - mccaincitizenship2008)

	*Euclidean
		gen citizenship2008prox_euclid1 = [(citizenship2008 - 2.977244)*(citizenship2008 - 2.977244) ] - [(citizenship2008 - 4.306098)*(citizenship2008 - 4.306098) ] 
		gen citizenship2008prox_euclid2 = [(citizenship2008 - 2.372263)*(citizenship2008 - 2.372263) ] - [ (citizenship2008 - 4.194245)*(citizenship2008 - 4.194245)] 
		gen citizenship2008prox_euclid3 = [(citizenship2008 - obamacitizenship2008)*(citizenship2008 - obamacitizenship2008) ] - [(citizenship2008 - mccaincitizenship2008)*(citizenship2008 - mccaincitizenship2008)] 

	summ citizenship2008prox citizenship2008prox_info citizenship2008prox_self citizenship2008prox_euclid1 citizenship2008prox_euclid2 citizenship2008prox_euclid3


*attitude strength*
	gen citizenship2008ext = . 
	replace citizenship2008ext = 1 if citizenship2008 == 4
	replace citizenship2008ext = 2 if citizenship2008 == 3
	replace citizenship2008ext = 2 if citizenship2008 == 5
	replace citizenship2008ext = 3 if citizenship2008 == 2
	replace citizenship2008ext = 3 if citizenship2008 == 6
	replace citizenship2008ext = 4 if citizenship2008 == 1
	replace citizenship2008ext = 4 if citizenship2008 == 7

	rename V083134 citizenship2008imp
	mvdecode citizenship2008imp, mv(-9 = . \ -8 = . \ -1 = . )
	tab citizenship2008imp

*standardized*
	foreach var in 	citizenship2008prox citizenship2008prox_info citizenship2008prox_self citizenship2008prox_euclid1 ///
		citizenship2008prox_euclid2 citizenship2008prox_euclid3  citizenship2008ext citizenship2008imp {
			qui sum `var'
			gen `var'01 = (`var' - `r(min)') / (`r(max)'-`r(min)')
		}

		label var citizenship2008prox01 "Path to Citi:Prox"
		label var citizenship2008imp01 "Path to Citi:Imp"
		
		
***Women Equal Role**
*own attitude, placements*
	rename V083166 women2008
	rename V083168a obamawomen2008
	rename V083168b mccainwomen2008
	mvdecode women2008 obamawomen2008 mccainwomen2008, mv(-1 = . \ -7 = . \ -8 = . \ -9 =. )

*proximity*
	*City Block: Sample
		summ *women2008
			*mccain 3.261738
			*obama 2.513889
		gen women2008prox = abs(women2008 - 2.513889) - abs(women2008 - 3.261738)

	*City Block: Informed
		summ *women2008 if info == 2	& int_knowl  >= 4 & int_knowl <= 5
			*mccain   2.840237
			*obama  2.160714
		gen women2008prox_info = abs(women2008 - 2.160714) - abs(women2008 -  2.840237)
		
	*City Block: Self
		gen women2008prox_self = abs(women2008 - obamawomen2008) - abs(women2008 - mccainwomen2008)
	*Euclidean
		gen women2008prox_euclid1 = [(women2008 - 2.513889)*(women2008 - 2.513889) ] - [(women2008 - 3.261738)*(women2008 - 3.261738) ] 
		gen women2008prox_euclid2 = [(women2008 - 2.160714)*(women2008 - 2.160714) ] - [ (women2008 -  2.840237)*(women2008 -  2.840237)] 
		gen women2008prox_euclid3 = [(women2008 - obamawomen2008)*(women2008 - obamawomen2008) ] - [(women2008 - mccainwomen2008)*(women2008 - mccainwomen2008) ] 

		summ women2008prox women2008prox_info women2008prox_self women2008prox_euclid1 women2008prox_euclid2 women2008prox_euclid3
	
*attitude strength*
	gen women2008ext = . 
	replace women2008ext = 1  if women2008 == 4
	replace women2008ext = 2  if women2008 == 3
	replace women2008ext = 2  if women2008 == 5
	replace women2008ext = 3  if women2008 == 2
	replace women2008ext = 3  if women2008 ==  6
	replace women2008ext = 4  if women2008 == 1 
	replace women2008ext = 4  if women2008 == 7


	rename V083167 women2008imp
	mvdecode women2008imp, mv(-9 = . \ -8 = . \ -1 =.)
	tab women2008imp

*standardized*
foreach var in 	women2008prox women2008prox_info women2008prox_self women2008prox_euclid1 ///
	women2008prox_euclid2 women2008prox_euclid3  women2008ext women2008imp {
		qui sum `var'
		gen `var'01 = (`var' - `r(min)') / (`r(max)'-`r(min)')
	}

	label var women2008prox01 "Women:Prox"
	label var women2008imp01 "Women:Imp"



**********Control Variables****************
*PID
rename V083098x pid
mvdecode pid, mv(-1 = . )
label var pid "PID"
summarize pid
gen pid01 = (pid - `r(min)') / (`r(max)'-`r(min)')
label var pid01 "PID"

*Ideology*
gen ideology = V083069
mvdecode ideology, mv(-7 = . \ -8 = . \ -9 = .) 
label var ideology "Ideology"
summarize ideology 
gen ideology01 = (ideology - `r(min)') / (`r(max)'-`r(min)')
label var ideology01 "Ideology"

gen ideology2 = V083069
replace ideology2 = . if ideology2 < 0
replace ideology2 = 8 if ideology2 == .
label var ideology2 "Ideology (Full)"
label def ideo1 8 "Haven't Thought Much/DK/NA" 1 "Ext. Liberal"  7 "Ext. Conservative" 4 "Moderate"
label values ideology2 ideo1

recode V083069 (1=1) (2=1) (3=1) (4=2) (5=3) (6=3) (7=3) ///
	(-9=4) (-8=4) (-7=4), gen(ideol)
	
	label var ideol "Ideology"
	label def id 1 "Liberal" 2 "Moderate" 3 "Conservative" 4 "Haven't Thought/DK/Ref"
	label values ideol id



*Race*
gen race = . 
replace race = 0 if V081102 == 1
replace race = 1 if V081102 == 2
replace race = 1 if V081102 == 4
replace race = 1 if V081102 == 6
replace race = 1 if V081102 == 5
replace race = 1 if V081102 == 7
label def rac 1 "Non-White" 0 "White"
label values race rac
label var race "Race"

gen hispanic = . 
replace hispanic = 1 if V083256a >=1 & V083256a <= 7
replace hispanic = 0 if V083256a < 0
label def his 1 "Hispanic" 0 "Non-Hispanic"
label values hispanic his
label var hispanic "Hispanic"

*Gender
gen gender = . 
replace gender = 1 if V081101 == 2
replace gender = 0 if V081101 == 1
label def gend 1 "Female" 0 "Male"
label values gender gend
label var gender "Gender"

*Age

rename V081104 age
mvdecode age, mv(-9 = . \ -8 = .)
summarize age
gen age01 = (age - `r(min)') / (`r(max)'-`r(min)')
label var age01 "Age"

*Education
gen educ = . 
replace educ = 1 if V083218x == 0
replace educ = 1 if V083218x == 1
replace educ = 1 if V083218x == 2
replace educ = 2 if V083218x == 3
replace educ = 3 if V083218x == 4
replace educ = 3 if V083218x == 5
replace educ = 4 if V083218x == 6
replace educ = 4 if V083218x == 7
label var educ "Education" 
label def ed 1 "< HS" 2 "HS" 3 "Some College" 4 "College+" 
label values educ ed

summarize educ
gen educ01 = (educ - `r(min)') / (`r(max)'-`r(min)')
label var educ01 "Education"



*Income
rename V083248 famincome
rename V083249 income
mvdecode famincome income, mv(-9 = . \ -8 = . \ -1 = .)



foreach var in income famincome {
		qui sum `var'
		gen `var'01 = (`var' - `r(min)') / (`r(max)'-`r(min)')

	}
	
label var famincome "Family Income"
label var income "Own Income"
label var income01 "Own Income"
label var famincome01 "Family Income"

egen income_pct = cut(income), group(10) label
gen income_miss = . 
replace income_miss = 1 if income == .
gen income_pct1 = income_pct 
replace income_pct1 = 10 if income_miss == 1 & income_pct1 == . 
label def inc_mis1 10 "Missing Income"
label values income_pct1 inc_mis1


egen famincome_pct = cut(famincome), group(10) label
gen famincome_miss = .
replace famincome_miss = 1 if famincome == . 
replace famincome_miss = 0 if famincome !=.

gen famincome_pct1 = famincome_pct 
replace famincome_pct1 = 10 if famincome_miss == 1 & famincome_pct1 == .
label def inc_mis2 10 "Missing Income" 
label values famincome_pct1 inc_mis2

*Retro Eval*

gen econ2008 = .
replace econ2008 = 1 if V083083x == 5
replace econ2008 = 2 if V083083x == 4
replace econ2008 = 3 if V083083x == 3
replace econ2008 = 4 if V083083x == 2
replace econ2008 = 5 if V083083x == 1

summarize econ2008
gen econ01 = (econ2008 - `r(min)') / (`r(max)'-`r(min)')
label var econ01 "Economic Eval"

*Traits*
label def trai 1 "Not Well at All" 4 "Extremely Well"
label def trai1 1 "Not Well at All" 5 "Extremely Well" 3 "Moderately Well"
*obama old
gen obama2008moralold = . 
replace obama2008moralold = 1 if V083099a == 4
replace obama2008moralold = 2 if V083099a == 3
replace obama2008moralold = 3 if V083099a == 2
replace obama2008moralold = 4 if V083099a == 1
tab obama2008moralold V083099a

gen obama2008knowlold = . 
replace obama2008knowlold = 1 if V083099d == 4
replace obama2008knowlold = 2 if V083099d == 3
replace obama2008knowlold = 3 if V083099d == 2
replace obama2008knowlold = 4 if V083099d == 1
tab obama2008knowlold V083099d

gen obama2008leaderold = . 
replace obama2008leaderold = 1 if V083099b == 4
replace obama2008leaderold = 2 if V083099b == 3
replace obama2008leaderold = 3 if V083099b == 2
replace obama2008leaderold = 4 if V083099b == 1
tab obama2008leaderold V083099b

*obama new*
gen obama2008moralnew = . 
replace obama2008moralnew = 1 if V083100a == 5
replace obama2008moralnew = 2 if V083100a == 4
replace obama2008moralnew = 3 if V083100a == 3
replace obama2008moralnew = 4 if V083100a == 2
replace obama2008moralnew = 5 if V083100a == 1
tab obama2008moralnew V083100a


gen obama2008knowlnew = . 
replace obama2008knowlnew = 1 if V083100d == 5
replace obama2008knowlnew = 2 if V083100d == 4
replace obama2008knowlnew = 3 if V083100d == 3
replace obama2008knowlnew = 4 if V083100d == 2
replace obama2008knowlnew = 5 if V083100d == 1
tab obama2008knowlnew V083100d

gen obama2008leadernew = . 
replace obama2008leadernew = 1 if V083100b == 5
replace obama2008leadernew = 2 if V083100b == 4
replace obama2008leadernew = 3 if V083100b == 3
replace obama2008leadernew = 4 if V083100b == 2
replace obama2008leadernew = 5 if V083100b == 1
tab obama2008leadernew V083100b



*mccain*
gen mccain2008moralold = .
replace mccain2008moralold = 1 if V083101a == 4
replace mccain2008moralold = 2 if V083101a == 3
replace mccain2008moralold = 3 if V083101a == 2
replace mccain2008moralold = 4 if V083101a == 1
tab mccain2008moralold V083101a

gen mccain2008knowlold = . 
replace mccain2008knowlold = 1 if V083101d == 4
replace mccain2008knowlold = 2 if V083101d == 3
replace mccain2008knowlold = 3 if V083101d == 2
replace mccain2008knowlold = 4 if V083101d == 1
tab mccain2008knowlold V083101d

gen mccain2008leaderold = . 
replace mccain2008leaderold = 1 if V083101b == 4
replace mccain2008leaderold = 2 if V083101b == 3
replace mccain2008leaderold = 3 if V083101b == 2
replace mccain2008leaderold = 4 if V083101b == 1
tab mccain2008leaderold V083101b



*mccain new*
gen mccain2008moralnew = .
replace mccain2008moralnew = 1 if V083102a == 5
replace mccain2008moralnew = 2 if V083102a == 4
replace mccain2008moralnew = 3 if V083102a == 3
replace mccain2008moralnew = 4 if V083102a == 2
replace mccain2008moralnew = 5 if V083102a == 1
tab mccain2008moralnew V083102a

gen mccain2008knowlnew = . 
replace mccain2008knowlnew = 1  if V083102d == 5
replace mccain2008knowlnew = 2  if V083102d == 4
replace mccain2008knowlnew = 3  if V083102d == 3
replace mccain2008knowlnew = 4  if V083102d == 2
replace mccain2008knowlnew = 5  if V083102d == 1
tab mccain2008knowlnew V083102d

gen mccain2008leadernew = . 
replace mccain2008leadernew = 1 if V083102b == 5
replace mccain2008leadernew = 2 if V083102b == 4
replace mccain2008leadernew = 3 if V083102b == 3
replace mccain2008leadernew = 4 if V083102b == 2
replace mccain2008leadernew = 5 if V083102b == 1
tab mccain2008leadernew V083102b

*Comparative Traits*
gen moral2008old = mccain2008moralold - obama2008moralold
gen knowl2008old = mccain2008knowlold - obama2008knowlold
gen leader2008old = mccain2008leaderold - obama2008leaderold

gen moral2008new = mccain2008moralnew - obama2008moralnew
gen knowl2008new = mccain2008knowlnew - obama2008knowlnew
gen leader2008new = mccain2008leadernew - obama2008leadernew



foreach var in moral2008old knowl2008old leader2008old moral2008new knowl2008new leader2008new {
		qui sum `var'
		gen `var'01 = (`var' - `r(min)') / (`r(max)'-`r(min)')
	}


gen moral2008both = moral2008old01
replace moral2008both = moral2008new01 if moral2008both == . 

gen knowl2008both = knowl2008old01
replace knowl2008both = knowl2008new01 if knowl2008both == . 

gen leader2008both = leader2008old01
replace leader2008both = leader2008new01 if leader2008both == .


	
	
